package com.lzq.springblog.controller;

import com.lzq.springblog.common.Result;
import com.lzq.springblog.common.ResultCode;
import com.lzq.springblog.service.LikeService;
import com.lzq.springblog.utils.JwtUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.Name;

@Tag(name = "点赞接口")
@Slf4j
@RequestMapping("/like")
@RestController
public class LikeController {

    @Autowired
    private LikeService likeService;

    @Operation(description = "是否点过赞")
    @GetMapping("/isliked")
    public Result isliked(Integer blogId, HttpServletRequest request) {
        log.info("开始执行isliked方法");
        String jwt = request.getHeader("user_token");
        Integer userId = (Integer) JwtUtils.getUserIdFromToken(jwt).getData();
        if (userId==null || userId<1) {
            log.error("查询的用户信息不存在");
            return Result.failed(ResultCode.FAILED);
        }
        //查是否点过赞
        Boolean result = likeService.isliked(userId,blogId);
        log.info("返回结果:{}",result);
        return Result.success(result);
    }
}
